<script setup lang='ts'>
import amapIcon from '@/static/amap.svg'
import { useUserStore } from '@/stores/useUserStore';
import { storeToRefs } from 'pinia';

interface IPoi {
  adcode: string // "360113"
  address: string // 丰和南大道696号
  adname: string
  citycode: string
  cityname: string
  id: string
  latitude: number // 纬度
  longitude: number // 经度
  name: string // 地区名称
  pcode: string
  photos: { url: string, title: string }[]
  pname: string
  postcode: string,
  extdata: {
    flag?: boolean // 是否是用户的标记
  }
}

const props = defineProps<IPoi>()

const emits = defineEmits(['addMarker', 'writeJournal', 'centerChange'])


const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore)

function handleAddMarker() {
  if (userInfo.value?.id) {
    emits("addMarker", props)
  } else {
    // 提示登录
    uni.showModal({
      title: '提示',
      content: '请先登录',
      success: function (res) {
        if (res.confirm) {
          uni.navigateTo({
            url: '/pages/login/login'
          })
        }
      }
    })

  }

}

function handleCenterChange() {
  emits("centerChange", props)
}

</script>

<template>
  <view class='space-panel-item__container pb-20' @click.stop="handleCenterChange">
    <view class="space-panel-item__info">
      <view class="front mr-20">
        <image class="img" style=" background-color: #eeeeee;" :src="photos[0]?.url || amapIcon">
        </image>
      </view>
      <view class="content">
        <view class="title">{{ name }}</view>
        <view class="address">地址：{{ address }}</view>
      </view>
    </view>
    <view class="space-panel-item__operate ml-12">
      <!-- 写日记 -->
      <!-- <uv-icon @click="handlewriteJournal" name="edit-pen-fill" class="mb-20" color="warning" size="54rpx"></uv-icon> -->
      <!-- 添加标记 -->
      <uv-icon @click="handleAddMarker" name="/static/si-glyph-golf-flag.svg" color="error" size="54rpx"></uv-icon>
    </view>
  </view>
</template>

<style scoped lang='scss'>
@import "@/styles/mixin/index.scss";
@import "./spacePanelItem.scss";
</style>